package com.quanquan.store.repository;

import com.quanquan.store.entity.Banner;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:BannerRepository
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/3/14 9:18
 * @Version 1.0
 */
public interface BannerRepository extends JpaRepository<Banner, String>, JpaSpecificationExecutor<Banner> {

    @Query(value = "SELECT * FROM oo_banner WHERE id = ?1 AND status_remove = 0", nativeQuery = true)
    Banner findByBannerId(String id);

    @Query(value="select * from oo_banner b left join  oo_banner_adsence ba on b.id=ba.banner_id where ba.status_remove=0 and ba.adsense_id=?1", nativeQuery = true)
    List<Banner> findByAdsenseId(String adsenseId, Pageable pageable);

    @Query(value="select * from oo_banner b where adsence_id = ?1 and status_remove = 0", nativeQuery = true)
    List<Banner> findByAdsenseIdNew(String adsenseId, Pageable pageable);

}
